Overview
This standalone script fetches comprehensive data for all NSE-listed ETFs (Exchange Traded Funds) from the ScanX API, including fundamental metrics, performance data, and ETF-specific fields like expense ratios.Why Standalone?
- Different Asset Class: ETFs have unique characteristics compared to stocks
- ETF-Specific Metrics: Requires fields like
ExpenseRatioandMfCoCodenot applicable to stocks - Separate Universe: ETF tracking is independent of equity stock analysis
- Infrequent Updates: ETF list changes less frequently than stock data needs refreshing
- Manual Trigger: Should be run when you need to update the ETF universe or check new ETF launches
What It Fetches
The script retrieves comprehensive fundamental and technical data for all NSE ETFs:Fundamental Fields
- Market Cap, P/E Ratio, P/B Ratio
- Dividend Yield
- Revenue, Revenue Growth (1 Year)
- Net Profit Margin, EBITDA Margin
- EPS, ROE, ROCE
ETF-Specific Fields
- Expense Ratio: Annual fund operating expense
- MfCoCode: Mutual Fund Company Code
- ISIN: International Securities Identification Number
Technical Fields
- Last Traded Price (LTP)
- Price changes (1 week, 1 month, 3 months, 1 year, 3 years, 5 years)
- Moving Averages (SMA 50, SMA 200)
- RSI (14-day)
- 52-week high and distance from it
- Volume
Output Files
Contains array of ETF objects with all fetched fields. Saved in the current working directory.
API Reference
fetch_all_etf_data()
Fetches all NSE ETFs from the ScanX API.
This function takes no parameters.
None (outputs to file)
API Endpoint:
OgInst: ETF- Filters for Exchange Traded Funds onlyExch: NSE- Restricts to NSE-listed ETFscount: 1000- High count to capture all ETFs in single request
- Uses
raise_for_status()to catch HTTP errors - Validates response structure before saving
- Catches and prints all exceptions
When to Run Manually
Initial Setup
Initial Setup
Run once when setting up the pipeline to get the complete ETF universe.
New ETF Launches
New ETF Launches
Check when new ETFs are launched (track AMC announcements).
Quarterly Review
Quarterly Review
Run quarterly to catch any new ETF listings and update expense ratios.
Portfolio Rebalancing
Portfolio Rebalancing
Before running ETF analysis or portfolio allocation scripts.
Usage
Source Code
Dependencies
requests: HTTP library for API callsjson: JSON serialization/deserializationos: (imported but not used in current version)
This script uses hardcoded headers similar to
fetch_fno_data.py. Consider refactoring to use get_headers() from pipeline_utils.py for better maintainability.ETF-Specific Considerations
Expense Ratio
The
ExpenseRatio field is critical for ETF evaluation. Lower expense ratios generally indicate better long-term returns for passive index ETFs.Tracking Error
While not directly fetched, you can calculate tracking error by comparing ETF price movements against its underlying index (from
fetch_all_indices.py).Liquidity
The
Volume field helps assess ETF liquidity - important for entry/exit execution quality.Integration Possibilities
While standalone, this data can be used for:- ETF screeners and comparison tools
- Passive investment strategy builders
- Tax-efficient portfolio construction
- Sector/thematic exposure analysis